﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TransFormer.BLL;

namespace TransFormer.Web.admin
{
    public partial class ProductTypeEdit : AdminPage
    {
        private BLL.ProductType _bll = new ProductType();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            int id;
            if (int.TryParse(Request["Id"], out id))
            {
                var modelList = _bll.GetModelList(string.Empty);
                parrentId.DataValueField = "Id";
                parrentId.DataTextField = "TypeName";
                parrentId.DataSource = modelList;
                parrentId.DataBind();

                var model = _bll.GetModel(id);
                txtTyepId.Text = model.Id.ToString();
                txtTypeName.Text = model.TypeName;
                txtDesc.Value = model.TypeDesc;
                parrentId.Items.FindByValue(model.ParrentId.ToString()).Selected = true;
                language.Items.FindByValue(model.Language).Selected = true;
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {

            Model.ProductType pt = new Model.ProductType();
            pt.Id = int.Parse(txtTyepId.Text);
            pt.TypeName = txtTypeName.Text;
            pt.TypeDesc = txtDesc.Value;
            pt.ParrentId = int.Parse(parrentId.Value);
            pt.Language = language.Value;
            _bll.Update(pt);
            Response.Redirect("producttypelist.aspx");


        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("producttypelist.aspx");

        }
    }
}